<template>
	<view class="searchPage">
		<!-- <u-navbar title="草稿"  :placeholder="true" leftIconColor="#fff" :autoBack="true" :bgColor="bgColor" :titleStyle="titleStyle"></u-navbar> -->
		<headerinfo></headerinfo>
		<view class="width60">
			<view class="content" v-if="listData.length > 0">
				<view class="card" v-for="(item, index) in listData" :key="index">
					<new-item @delOver="delOver" :newIndex="index" :new="item" :isMylife="sureisMylife" :myarticle="true"
						:isdraft="true"></new-item>
				</view>
			</view>
			<nodata v-if="listData.length == 0 && loadingOver"></nodata>
			<view class="nomore" v-if="listOver" style="background-color: #fff;">
				没有更多了 ~</view>
		</view>

	</view>
</template>

<script>
	import newItem from '@/components/new-item.vue';
	export default {
		components: {
			newItem
		},
		data() {
			return {
				loadingOver: false,
				query: {
					pageSize: 10,
					isDraft: true,
					lastDocId: '',
					categoryIds: []
				},
				listData: [],
				listOver: false,
				isMylife: '',
				sureisMylife: false
			};
		},
		onPullDownRefresh() {
			this.query.lastDocId = '';
			this.getData();
		},
		onReachBottom() {
			if (!this.listOver) {
				this.getData();
			}
		},
		onLoad(e) {
			if (e.isMylife) {
				this.isMylife = e.isMylife
				this.sureisMylife = true
			} else {
				this.isMylife = ''
				this.sureisMylife = false
			}
			this.getData();
		},
		onShow() {
			// this.query.lastDocId = '';
			// this.getData();
		},
		methods: {
			delOver(index) {
				console.log(index)
				this.listData.splice(index, 1)
			},
			getData() {
				uni.showLoading({
					title: '加载中...'
				});
				this.loadingOver = false;
				if (this.isMylife == 1) {
					this.$api.queryLives(this.query).then(res => {
						console.log(res);

						if (res.lastDocId) {
							this.query.lastDocId = res.lastDocId;
							this.listData = [...this.listData, ...res.list];
						} else {
							this.query.lastDocId = '';
							this.listData = res.list;
						}

						if (res.list.length < this.query.pageSize) {
							this.listOver = true;
						}
						this.loadingOver = true;
						this.$forceUpdate()
						uni.hideLoading();
						uni.stopPullDownRefresh();
					});
				} else {
					console.log('this.query',this.query);
					this.$api.queryArticles(this.query).then(res => {
						if (res.lastDocId) {
							this.query.lastDocId = res.lastDocId;
						} 
						this.listData = [...this.listData, ...res.list];
						if (res.list.length < this.query.pageSize) {
							this.listOver = true;
						}
						this.loadingOver = true;
						uni.hideLoading();
						uni.stopPullDownRefresh();
					});
				}

			}
		}
	};
</script>


<style lang="scss" scoped>
	.searchPage {
		.content {}

		.card {
			margin: 0 auto;

		}
	}
</style>